package com.lagou;

import com.lagou.bean.ConsumerComponent;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;

public class DubboConsumerMain {
    public static void main(String[] args) {

        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);

        context.start();

        ConsumerComponent service = context.getBean(ConsumerComponent.class);

        //编写一个消费端程序，不断调用Dubbo服务的3个方法
        while (true) {
            try {

                String hello = service.sayHello("tom", 100);
                System.out.println("-----result :" + hello);
                String goodBye = service.sayGoodBye("tom", 100);
                System.out.println("-----result :" + goodBye);
                String goodNight = service.sayGoodNight("tom", 100);
                System.out.println("-----result :" + goodNight);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan("com.lagou.bean")
    @EnableDubbo
    static class ConsumerConfiguration {

    }
}
